@extends('adminDialog')

@section('content')
    <form action="{{url('admin/sys/updates/'.$model->id)}}" method="POST" class="J_ajaxForm">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <div class="pop_cont pop_table" style="overflow-y: scroll;height: 529px;">
            <table width="100%">
                <tbody>
                <tr>
                    <th><label for="title">显示位置 <span class="red">*</span></label></th>
                    <td>
                        <input type="text" name="name" id="name" class="input length_6" value="{{$model->name}}"/>
                    </td>
                </tr>
                <tr id="type_select" style="display: none;">
                    <th><label for="title">显示类型 <span class="red">*</span></label></th>
                    <td>
                        <input type="radio" name="type" value="0" {{"#" != substr($model->val,0,1) ? "checked='checked'" : ""}}/>图片
                        <input type="radio" name="type" value="1" {{"#" == substr($model->val,0,1) ? "checked='checked'" : ""}}/>颜色
                    </td>
                </tr>
                <tr id="up_pic" {!! "#" == substr($model->val,0,1) ? 'style="display:none"' : '' !!}>
                    <th><label for="">图</label></th>
                    <td>
                        <a href="javascript:javascript();" id="pickfiles" class="pickfiles" title="选择上传文件">
                            <input type="hidden" name="val" value="{{$model->val}}" {!! "#" == substr($model->val,0,1) ? 'disabled' : '' !!}/>
                            <img style="width: 300px;height: 256px;" src="{{ $model->val }}"/>
                        </a>
                    </td>
                </tr>
                <tr id="select_color" {!! "#" != substr($model->val,0,1) ? 'style="display:none"' : '' !!}>
                    <th><label for="">颜色</label></th>
                    <td>
                        <input type="color" name="val" value="{{$model->val}}" {!! "#" != substr($model->val,0,1) ? 'disabled' : '' !!}/>
                    </td>
                </tr>
                <tr>
                    <th><label>链接</label></th>
                    <td>
                        <select name="link">
                            <option style="width: 5em;" value="0">--请选择--</option>
                            @foreach($types as $key=>$item)
                                <option value="{{$key}}"  @if($model->link == $key) selected="selected" @endif    >{{$item["name"]}}</option>
                            @endforeach
                        </select>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>

        <div class="pop_bottom cc">
            <button type="reset" class="btn fr" id="J_dialog_close">取消</button>
            <button type="submit" class="btn btn_submit J_ajax_submit_btn fr mr10" id="J_dialog_close">提交</button>
        </div>
    </form>
@stop

@section('style')
    <style type="text/css">
        .body_none {
            width: 720px;
        }
        .pop_cont table tr th{ width: 20%; }

    </style>
@stop

@section('js')
    @parent
    @include('UEditor::head')
    <script src="{{ asset('js/plupload/plupload.full.min.js') }}"></script>
    <script>
        $(function(){
            $('#type_select input').on('click',function(){
                if(0 == $(this).val()){
                    $('#up_pic').css('display','block');
                    $('#select_color').css('display','none');
                } else {
                    $('#up_pic').css('display','none');
                    $('#select_color').css('display','block');
                }
            })
        });
        var ue = UE.getEditor('container', {
            initialFrameWidth: 600, initialFrameHeight: 150, autoHeightEnabled: false, toolbars: [
                ['source', 'undo', 'redo', 'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc'],
                ['link', 'simpleupload', 'insertimage']
            ]
        });
        ue.ready(function () {
            ue.execCommand('serverparam', '_token', GV.TOKEN);//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值.
        });
    </script>
    <script>
        $(function () {
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'pickfiles', // you can pass in id...
                //container: document.getElementById('container'), // ... or DOM Element itself
                url: "{{ url('uploadConfigimg') }}",
                filters: {
                    max_file_size: '5mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ]
                },
                multi_selection: false,
                file_data_name: 'file',
                multipart_params: {'_token': '{{ csrf_token() }}', 'id': '{{$model->id}}'},
                // Flash settings
                flash_swf_url: '{{ asset("js/plupload/Moxie.swf") }}',
                // Silverlight settings
                silverlight_xap_url: '{{ asset('js/plupload/Moxie.xap') }}',
                init: {
                    PostInit: function () {
                        return false;
                    },
                    FilesAdded: function (up, file) {
                        $('.up-pic img').attr('src', '{{ asset('images/loading.gif') }}');
                        uploader.start();
                    },
                    Error: function (up, err) {
                        alert(err.message);
                    },
                    FileUploaded: function (up, file, responseObj) {
                        var response = $.parseJSON(responseObj.response);
                        if (response.state == 'success') {
                            $('.pickfiles img').attr('src', '{!! url("' + response.val + '") !!}');
                            $('.pickfiles input').val(response.val);
                        } else {
                            alert(response.message);
                        }
                    }
                }
            });
            uploader.init();
        });
    </script>
@stop
